/**
 * 
 */
package com.huarui.desktop;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.ewaf.framework.action.BaseAction;

import com.opensymphony.xwork2.Action;

/**
 * @author sunpeng
 * 
 */
public class NotepadAction extends BaseAction {
	private static final long serialVersionUID = 2659262537445018751L;
	private String userId;
	private String text;
	private Map<String,String> jsonResult; // JSON Result默认读取jsonResult名称属性
	private static final Map<String, String> datus = new HashMap<String, String>();

	public String save() throws Exception {
		if (StringUtils.isNotEmpty(this.userId)) {
			datus.put(this.userId, this.text);
		}
		this.jsonResult=new HashMap<String,String>();
		this.jsonResult.put("code","200");
		return Action.SUCCESS;
	}

	public String clear() throws Exception {
		this.text = "";
		if (StringUtils.isNotEmpty(this.userId)) {
			datus.put(this.userId, this.text);
		}
		this.jsonResult=new HashMap<String,String>();
		this.jsonResult.put("code","200");
		return Action.SUCCESS;
	}

	public String view() throws Exception { 
		String data=datus.get(this.userId);
		this.jsonResult=new HashMap<String,String>();
		this.jsonResult.put("text",data==null?"":data);
		this.jsonResult.put("code","200");
		return Action.SUCCESS;
	}
	
	public Map<String,String> getJsonResult()
	{
		return this.jsonResult;
	}

	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}

	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}

}
